package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ${郭冬胜}
 * @date 2025/7/12 9:55
 */
@RestController
public class UserCaontroller {
    @Autowired
    UserService userService;
    @RequestMapping("/full")
    public Object full(String newDate){
        List<Map> full = userService.full(newDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",full.get(0).get("sum(amount)"));
        return jsonObject;
    }
    @RequestMapping("/fullA")
    public Object fullA(String newDate){
        List<Map> full = userService.fullA(newDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",full.get(0).get("sum(amount)"));
        return jsonObject;
    }
    @RequestMapping("/fullB")
    public Object fullB(String newDate){
        List<Map> full = userService.fullB(newDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray objects = new JSONArray();
        for (Map map : full) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("a"));
            objects.add(jsonObject1);
        }
        data.put("mapData",objects);
        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/fullC")
    public Object fullC(String newDate){
        List<Map> maps = userService.fullC(newDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray objects = new JSONArray();
        for (Map map : maps) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("b"));
            objects.add(jsonObject1);
        }
        jsonObject.put("data",objects);
        return jsonObject;
    }
    @RequestMapping("/fullD")
    public Object fullD(String newDate){
        List<Map> maps = userService.fullD(newDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray objects = new JSONArray();

            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name","张三");
            jsonObject1.put("value",maps.get(0).get("c"));
            objects.add(jsonObject1);

            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("name","李四");
            jsonObject2.put("value",maps.get(1).get("c"));
            objects.add(jsonObject2);

            JSONObject jsonObject3 = new JSONObject();
            jsonObject3.put("name","王五");
            jsonObject3.put("value",maps.get(2).get("c"));
            objects.add(jsonObject3);

        jsonObject.put("data",objects);
        return jsonObject;
    }
    @RequestMapping("/fullE")
    public Object fullE(String newDate,String status,String name){
        List<Map> maps = userService.fullE(newDate, status, name);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray objects = new JSONArray();
        for (Map map : maps) {
            objects.add(map.get("name"));
        }
        data.put("categories",objects);

        JSONArray objects1 = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","各城市");
        JSONArray objects2 = new JSONArray();
        for (Map map : maps) {
            objects2.add(map.get("d"));
        }
        jsonObject1.put("data",objects2);
        objects1.add(jsonObject1);


        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/fullF")
    public Object fullF(String newDate,String status){
        List<Map> maps = userService.fullF(newDate,status);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();

        JSONArray objects = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","各城市");
        jsonObject1.put("id","subsys");
        objects.add(jsonObject1);

        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","各部门");
        jsonObject2.put("id","module");
        objects.add(jsonObject2);

        data.put("columns",objects);

        JSONArray objects1 = new JSONArray();
        for (Map map : maps) {
            JSONObject jsonObject3 = new JSONObject();
            jsonObject3.put("subsys",map.get("name"));
            jsonObject3.put("module",map.get("e"));
            objects1.add(jsonObject3);
        }

        data.put("rows",objects1);

        jsonObject.put("data",data);
        return jsonObject;
    }
}
